<?php

namespace App\Http\Controllers\Util;

use App\services\OSS;
use Illuminate\Http\Request;
use App\Http\Controllers\Controller;

class UploadController extends Controller
{
    public function upload(Request $request)
    {
        //获取上传的文件
        
        $file = $request->file('file');
        //获取上传图片的临时地址
//        dd($file);
        $path = $file->getRealPath();
        //生成文件名
        $fileName = date('ymd') . $file->getFilename() . time() . '.' . $file->getClientOriginalExtension();
        //阿里上传图片
        OSS::publicUpload('mengju1', $fileName, $path, ['ContentType' => $file->getClientMimeType()]);
        $Url = OSS::getPublicObjectURL('mengju1', $fileName);
        return ['code' => 0, 'msg' => '上传成功', 'data' => ['src' => $Url]];
    }
}
